<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="utf-8" />
        <title>Simple example - Editor.md examples</title>
        <link rel="stylesheet" href="js/md-master/css/editormd.css" />
		<script src="js/md-master/examples/js/jquery.min.js"></script>
		<script type="text/javascript" src="/script.js"></script> 
		<script type="text/javascript" src="/layer/layer.js"></script>
		<script src="js/md-master/editormd.min.js"></script>
		
<script>
function saveNote(){
	if ($("#noteTitle").val()==""){
		layer.msg("Title is not allow empty");
		return false;
	}
	if ($("#noteId").val()==""){
		client.query('insert into note (title,content) values (?,?) ',[$("#noteTitle").val(),$("#noteContent").val()],function(err1, results1){
			if(results1.affectedRows >0){
				layer.msg("add success affect "+results1.affectedRows+" rows ");
			}
		});
	}else{
		client.query('update note set title=?,content=? where id=? ',[$("#noteTitle").val(),$("#noteContent").val(),$("#noteId").val()],function(err1, results1){
			if(results1.affectedRows >0){
				layer.msg("update success affect "+results1.affectedRows+" rows ");
			}
		});
	}
}


</script>
    </head>
    <body>
        <div id="layout">
            <header>
			<input type="hidden" value="" id="noteId" />
		title:<input type="text" id="noteTitle" style="width:600px" />
		<input type="button" value="save" onclick="saveNote();"/>
            </header>
            <div id="test-editormd">
                <textarea id="noteContent" style="display:none;"></textarea>
            </div>
        </div>
<script type="text/javascript">
var testEditor;

$(function() {
	//show();
	
	/*
	// or
	testEditor = editormd({
		id      : "test-editormd",
		width   : "90%",
		height  : 640,
		path    : "../lib/"
	});
	*/
});
function show(){
	if (parent.indexNodeId){
	
		client.query('select * from note where id=? ',[parent.indexNodeId],function(err1, results1){
		console.info(results1);
			if(results1.length >0){
				$("#noteTitle").val(results1[0].title);
				$("#noteContent").val(results1[0].content);
				$("#noteId").val(results1[0].id);
				showEdit();
			}
		});
	}else{
			showEdit();
	}
	
}

function showEdit(){
	testEditor = editormd("test-editormd", {
					width   : "90%",
					height  : 640,
					syncScrolling : "single",
					path    : "js/md-master/lib/"
				});
}
</script>
    </body>
</html>